package model;

import java.util.ArrayList;

import model.enemies.CreateEnemiesThread;
import model.surface.Scale;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.example.towerdefence.R;
import controller.GameBoard;

/**
 * Creates each wave with different image.
 * 
 * @author EvilTeam
 * 
 */
public class CreateWaves {
	private ArrayList<Bitmap> imagesForWaves = new ArrayList<Bitmap>();
	private static final int HOW_MANY_MONSTERS = 10;
	private static final int HOW_MANY_LEVELS = 20;

	public CreateWaves() {
		createImagesForLevels();
		createWave();
	}
	/**
	 * Set image for each wave.
	 */
	private void createImagesForLevels() {
		for (int level = 0; level <= 10; level++) {
			Bitmap image = null;
			switch (level) {
			case 0:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.firstbossfenix);
				imagesForWaves.add(image);
				break;
			case 1:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.ironman);
				imagesForWaves.add(image);
				break;
			case 2:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.hawkeye);
				imagesForWaves.add(image);
				break;
			case 3:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.captainamericashield);
				imagesForWaves.add(image);
				break;
			case 4:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.loki);
				imagesForWaves.add(image);
				break;
			case 5:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.thirdbossifrit);
				imagesForWaves.add(image);
				break;
			case 6:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.hulk);
				imagesForWaves.add(image);
				break;
			case 7:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.nickfury);
				imagesForWaves.add(image);
				break;
			case 8:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.blackwidow);
				imagesForWaves.add(image);
				break;
			case 9:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.thor);
				imagesForWaves.add(image);
				break;
			case 10:
				image = BitmapFactory.decodeResource(GameBoard.getRes(),
						R.drawable.lastbossbahamut);
				imagesForWaves.add(image);
				break;
			}
		}
	}

	/**
	 * Create all waves.
	 */
	public void createWave() {
		for (int level = 0; level <= HOW_MANY_LEVELS; level++) {
			int imageForLevel = level;
			if (imageForLevel > HOW_MANY_MONSTERS)
				imageForLevel -= HOW_MANY_MONSTERS;

			addNewWaveInThreadsArray(level,
					this.getImagesForWaves().get(imageForLevel));
		}
	}

	/**
	 * Create thread for each level and add it to DataHolder's array.
	 * 
	 * @param level
	 * @param imageForEnemy
	 */
	private void addNewWaveInThreadsArray(int level, Bitmap imageForEnemy) {
		if (level == 0) {
			DataHolder.addThread(new CreateEnemiesThread(
					DataHolder.getEnemies(), imageForEnemy, Scale.getScreenHeight(),
					null, 0));
		} else
			DataHolder.addThread(new CreateEnemiesThread(
					DataHolder.getEnemies(), imageForEnemy, Scale.getScreenHeight(),
					DataHolder.getThreads().get(level - 1), level));
	}

	public ArrayList<Bitmap> getImagesForWaves() {
		return imagesForWaves;
	}
}
